import Vue from "vue";
import CryptoJS from 'crypto-js'
import Cookies from "js-cookie";
import Element from "element-ui";
Element.Dialog.props.closeOnClickModal.default = false;
import "./assets/styles/element-variables.scss";

import "./assets/styles/index.scss"; // global css
import "./assets/styles/ruoyi.scss"; // ruoyi css
import App from "./App";
import store from "./store";
import router from "./router";
import directive from "./directive"; //directive
import plugins from "./plugins"; // plugins

import "./assets/icons"; // icon
import "./permission"; // permission control
import { getDicts,updateData } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import {
  parseTime,
  resetForm,
  addDateRange,
  selectDictLabel,
  selectDictLabels,
  isTimeExpired,
  handleTree,
  arrayToObject,
  generateUUID,
} from "@/utils/ruoyi";
import {
  compressImage
} from "@/utils/compressImage";
import { checkPermi } from "@/utils/permission";
import commonMaps from "@/utils/commonMaps";
import VueClipboard from "vue-clipboard2";

Vue.use(VueClipboard);

// // 预览组件
// import preview from 'vue-photo-preview'
// import 'vue-photo-preview/dist/skin.css'
// let options = {
//   fullscreenEl: false, //控制是否显示右上角全屏按钮
//   closeEl: true, //控制是否显示右上角关闭按钮
//   tapToClose: true, //点击滑动区域应关闭图库
//   shareEl: false, //控制是否显示分享按钮
//   zoomEl: true, //控制是否显示放大缩小按钮
//   counterEl: true, //控制是否显示左上角图片数量按钮
//   tapToToggleControls: true, //点击应切换控件的可见性
//   clickToCloseNonZoomable: false, //点击图片应关闭图库，设置无效
//   indexIndicatorSep: ' / ', //图片数量的分隔符
//   bgOpacity: 0.8, // 背景透明度
// }
// Vue.use(preview, options)
// Vue.use(preview)

// import infiniteScroll from 'vue-infinite-scroll'
// Vue.use(infiniteScroll)

// // 分页组件
import Pagination from "@/components/Pagination";
// // 自定义表格工具组件
// import RightToolbar from "@/components/RightToolbar";
// import ZdyRightToolbar from "@/components/ZdyRightToolbar";

// // 富文本组件
// import Editor from "@/components/Editor";
// // 文件上传组件
// import FileUpload from "@/components/FileUpload";
// // 图片上传组件
// import ImageUpload from "@/components/ImageUpload";
// // 字典标签组件
import DictTag from "@/components/DictTag";
// 头部标签组件
// import VueMeta from "vue-meta";
// 字典数据组件
import DictData from "@/components/DictData";
// import $ from "jquery";
// import "default-passive-events";

// 弹窗小标题组件
import formSubTitVue from "@/views/tenantPages/components/formSubTit.vue";

// window.jQuery = $;
// window.$ = $;
import youzhiName from "@/components/common/youzhiName.vue";

// 自己封装的上传一张图片的组件
import uploadImageOne from "@/components/upload/uploadImageOne.vue";
// 封装一个回显图片的组件
import imgBox from "./components/imgBox.vue";
// 封装一个多选框组的组件
import myCheckbox from "./components/myCheckbox"

Vue.prototype.commonMaps = commonMaps;
// 全局方法挂载
Vue.prototype.getDicts = getDicts;
Vue.prototype.getConfigKey = getConfigKey;
Vue.prototype.parseTime = parseTime;
Vue.prototype.resetForm = resetForm;
Vue.prototype.addDateRange = addDateRange;
Vue.prototype.selectDictLabel = selectDictLabel;
Vue.prototype.selectDictLabels = selectDictLabels;
Vue.prototype.isTimeExpired = isTimeExpired;
Vue.prototype.handleTree = handleTree;
Vue.prototype.checkPermi = checkPermi;
// Vue.prototype.priceReg = /^(?:[1-9]\d*(?:\.\d{1,2})?|0(?:\.\d{1,2})?)?$/;
Vue.prototype.priceReg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
Vue.prototype.phoneReg = /^1[3-9][0-9]\d{8}$/;
Vue.prototype.idCardReg = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
Vue.prototype.arrayToObject = arrayToObject;
Vue.prototype.generateUUID = generateUUID;
Vue.prototype.compressImage = compressImage;
// 格式化日期时间
Vue.prototype.$formatDate = function(time) {
  if (!time) return ''
  const date = new Date(time)
  const year = date.getFullYear()
  const month = String(date.getMonth() + 1).padStart(2, '0')
  const day = String(date.getDate()).padStart(2, '0')
  const hours = String(date.getHours()).padStart(2, '0')
  const minutes = String(date.getMinutes()).padStart(2, '0')
  const seconds = String(date.getSeconds()).padStart(2, '0')
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
};
// 参数签名
// AES-ECB加密
Vue.prototype.encryptAESAndMD5 =function encryptAESAndMD5(plaintext, key) {
  // 1. AES-ECB加密
    var keyHex = CryptoJS.enc.Utf8.parse(key);
    var content = CryptoJS.enc.Utf8.parse(plaintext);
    var encrypted = CryptoJS.AES.encrypt(content, keyHex, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    });
    // 获取加密后的Base64字符串
    const encryptedData = encrypted.ciphertext;
    var ciphertextBase64 = encryptedData.toString(CryptoJS.enc.Hex);
    // 2. 计算MD5哈希
    var md5Hash = CryptoJS.MD5(ciphertextBase64).toString();
    return md5Hash;
}
// 根据身份证获取年龄
Vue.prototype.getAge = function (identityCard) {
  let len = (identityCard + "").length;
  let strBirthday = "";
  if (len == 18) {
    //处理18位的身份证号码从号码中得到生日和性别代码
    strBirthday =
      identityCard.substr(6, 4) +
      "/" +
      identityCard.substr(10, 2) +
      "/" +
      identityCard.substr(12, 2);
  }
  if (len == 15) {
    let birthdayValue = "";
    birthdayValue = identityCard.charAt(6) + identityCard.charAt(7);
    if (parseInt(birthdayValue) < 10) {
      strBirthday =
        "20" +
        identityCard.substr(6, 2) +
        "/" +
        identityCard.substr(8, 2) +
        "/" +
        identityCard.substr(10, 2);
    } else {
      strBirthday =
        "19" +
        identityCard.substr(6, 2) +
        "/" +
        identityCard.substr(8, 2) +
        "/" +
        identityCard.substr(10, 2);
    }
  }
  let birthDate = new Date(strBirthday);
  let nowDateTime = new Date();
  let age = nowDateTime.getFullYear() - birthDate.getFullYear();
  //再考虑月、天的因素;.getMonth()获取的是从0开始的，这里进行比较，不需要加1
  if (
    nowDateTime.getMonth() < birthDate.getMonth() ||
    (nowDateTime.getMonth() == birthDate.getMonth() &&
      nowDateTime.getDate() < birthDate.getDate())
  ) {
    age--;
  }
  return age;
}


// // 正式环境  erp域名
Vue.prototype.erpHost =
  process.env.NODE_ENV === "development"
    ? "http://192.168.3.101:808"
    : "https://erp.yuduhulian.com/chat/erp";


import elTableSticky from '@cell-x/el-table-sticky'

Vue.use(elTableSticky)

// // 全局组件挂载
Vue.component("uploadImageOne", uploadImageOne);
Vue.component("imgBox", imgBox);
Vue.component("youzhiName", youzhiName);
Vue.component("DictTag", DictTag);
Vue.component("Pagination", Pagination);
Vue.component("formSubTitVue", formSubTitVue);
Vue.component("myCheckbox", myCheckbox);
// Vue.component("RightToolbar", RightToolbar);
// Vue.component("ZdyRightToolbar", ZdyRightToolbar);
// Vue.component("Editor", Editor);
// Vue.component("FileUpload", FileUpload);
// Vue.component("ImageUpload", ImageUpload);

Vue.use(directive);
Vue.use(plugins);
// Vue.use(VueMeta);
DictData.install();

// 引用图片预览插件
import "viewerjs/dist/viewer.css";
import VueViewer from "v-viewer";
Vue.use(VueViewer, {
  defaultOptions: {
    zIndex: 9999,
  },
});
// 全局变量
// Vue.prototype.h5Url = 'http://ikbh.top/show.html?ZHID=';
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

Vue.use(Element, {
  size: Cookies.get("size") || "medium", // set element-ui default size
});

Vue.config.productionTip = false;

new Vue({
  el: "#app",
  router,
  store,
  render: (h) => h(App),
});
